package com.hl.web;

import com.github.pagehelper.PageInfo;
import com.hl.pojo.Article;
import com.hl.service.ArticleService;
import com.hl.util.GeneralResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/article")
@CrossOrigin
public class ArticleController {
    @Autowired
    private ArticleService articleService;

    private String path;
    @RequestMapping("/getAllArticleMessage")
    public GeneralResult getAllArticleMessage(){
        //调用对象
        List<Article> list = articleService.getAllArticleMessage();
        System.out.println(list);
        //返回数据
        return GeneralResult.success(list);
    }

    @RequestMapping("/souSuoArticleMessage")
    public GeneralResult souSuoArticleMessag(@RequestBody Map<String,Object> map){
        System.out.println(map);
        GeneralResult res = articleService.souSuoArticleMessage(map);
        return res;
    }

    @RequestMapping("/xinZengArticleMessage")
    public GeneralResult xinZengArticleMessage(@RequestBody Map<String,Object> map){
        System.out.println(map);
        GeneralResult res = articleService.xinZengArticleMessage(map);
        return res;
    }

    @RequestMapping("/shanChuArticleMessage")
    public GeneralResult shanChuArticleMessage(Integer id){
        GeneralResult res = articleService.shanChuArticleMessage(id);
        return res;
    }

    @RequestMapping("/xiuGaiArticleMessage")
    public GeneralResult xiuGaiArticleMessage(@RequestBody Map<String,Object> map){
        GeneralResult res = articleService.xiuGaiArticleMessage(map);
        return res;
    }

    @RequestMapping("/upload")
    public GeneralResult upload(MultipartFile file) throws IOException {
        file.transferTo(new File("D:\\JavaProjects\\03_SpringMVC\\sfzy项目\\vue\\vue\\sfzy\\public\\images\\" + file.getOriginalFilename()));
        path = "/images/" + file.getOriginalFilename();
        System.out.println(path);
        return GeneralResult.message(200,"上传成功",null);
    }

    @RequestMapping("/queDingShangChuan")
    public GeneralResult queDingShangChuan(){
        GeneralResult res = articleService.queDingShangChuan(path);
        return res;
    }
}
